****
****
****	PSID_script.do
****
****
****	Replication file for anlyses of PSID for:
****		
****	"Intersectionality, Depression, and Voter Turnout"
****
****	by Christopher Ojeda and Christine Slaughter
****
****
****	Table of Contents
****
****	- Section 1: Data prep
****
****	- Section 2: Analyses
****


********************************************************************************
****** Section 1: Data Prep

**
** Vote
recode vote2005 5=0
recode vote2007 5=0
recode vote2009 0=. 5=0 9=.
recode vote2011 0=. 5=0

**
** Depression
forvalues i=2005(2)2011{
foreach var of varlist depress_effort`i' depress_hopeless`i' depress_nervous`i' depress_restless`i' depress_sad`i' depress_worthless`i'{
replace `var' = . if `var' == 9
recode `var' 5=0 4=1 3=2 2=3 1=4
}
alpha depress_effort`i' depress_hopeless`i' depress_nervous`i' depress_restless`i' depress_sad`i' depress_worthless`i', std item
}
*

forvalues i=2005(2)2011{
egen depression`i' = rowmean(depress_effort`i' depress_hopeless`i' depress_sad`i' depress_worthless`i')
}
*

sum depression*

forvalues i=2005(2)2011{
gen depress_top`i' = 0
replace depress_top`i' = 1 if depression`i' > 1
replace depress_top`i' = . if depression`i' == .
}
*

**
** Gender
gen female = sex
recode female 2=1 1=0

**
** Race
foreach var of varlist race*{
replace `var' = . if `var' == 0 | `var' == 8 | `var' == 9
}
*

forvalues i = 2005(2)2011{
replace racea`i' = 1 if racea`i' == . & raceb`i' == 1
replace racea`i' = 2 if racea`i' == . & raceb`i' == 2
replace racea`i' = 3 if racea`i' == . & raceb`i' == 3
replace racea`i' = 4 if racea`i' == . & raceb`i' == 4
replace racea`i' = 5 if racea`i' == . & raceb`i' == 5
replace racea`i' = 7 if racea`i' == . & raceb`i' == 7
replace racea`i' = 1 if racea`i' == . & racec`i' == 1
replace racea`i' = 2 if racea`i' == . & racec`i' == 2
replace racea`i' = 3 if racea`i' == . & racec`i' == 3
replace racea`i' = 4 if racea`i' == . & racec`i' == 4
replace racea`i' = 5 if racea`i' == . & racec`i' == 5
replace racea`i' = 7 if racea`i' == . & racec`i' == 7
rename racea`i' race`i'
gen race_white`i' = 0
replace race_white`i' = 1 if race`i' == 1
replace race_white`i' = . if race`i' == .
gen race_black`i' = 0
replace race_black`i' = 1 if race`i' == 2
replace race_black`i' = . if race`i' == .
}
*

forvalues i = 2005(2)2011{
drop if race`i' == 3 | race`i' == 4 | race`i' == 5 | race`i' == 7
}
*

gen race_black = race_black2011
replace race_black = race_black2009 if race_black == .
replace race_black = race_black2007 if race_black == .
replace race_black = race_black2005 if race_black == .

**
** Age
foreach var of varlist age2005 age2007 age2009 age2011{
replace `var' = . if `var' == 0
}
*

**
** Education
foreach var of varlist educ_years2005 educ_years2007 educ_years2009 educ_years2011{
replace `var' = . if `var' == 0 | `var' == 99 | `var' == 98
}
*

**
** Income
/*Constructed as family income divided by family needs standard; the needs
standard is based on the Census Bureaus poverty level according to household size,
age, and composition. */
forvalues i=1968(1)1997{
gen pov_level`i' = inc_fam`i'/pov_needs`i'
}

forvalues i=1999(2)2011{
gen pov_level`i' = inc_fam`i'/pov_needs`i'
}
*

* Log of poverty level
/*I log the poverty level consistent with research showing that the effect
of economic status on political participation is curvilinear (Rosenstone 1982)*/
gen pov_levell2005 = log(pov_level2005 + .001)
gen pov_levell2007 = log(pov_level2007 + .001)
gen pov_levell2009 = log(pov_level2009 + .001)
gen pov_levell2011 = log(pov_level2011 + .001)

**
** Church attend
foreach var of varlist church_attend2005 church_attend2007 church_attend2009 church_attend2011{
replace `var' = . if `var' == 8 | `var' == 9
replace `var' = 1 if `var' == 0
}
*

**
** Marital Status
forvalues i=2005(2)2011{
gen married`i' = 0
replace married`i' = 1 if marital`i' == 1
replace married`i' = . if marital`i' == .
}
*

**
** Health
forvalues i=2005(2)2011{
replace health_self`i' = . if health_self`i' == 9
recode health_self`i' 5=0 4=1 3=2 2=3 1=4
}
*

**
** Health Insurance
drop health_ins1999 health_ins2001 health_ins2013 health_ins2015
sum health_ins*
foreach var of varlist health_ins*{
replace `var' = . if `var' == 8 | `var' == 9
recode `var' 5=0
}
*

**
** Group Consciousness
drop ethnic_imp2013 ethnic_imp2015
sum ethnic_imp*
foreach var of varlist ethnic_imp*{
replace `var' = . if `var' == 8 | `var' == 9
}
*

**
** Intersectional Groups
gen inter_cat = .
replace inter_cat = 1 if female == 0 & race_black == 0
replace inter_cat = 2 if female == 1 & race_black == 0
replace inter_cat = 3 if female == 0 & race_black == 1
replace inter_cat = 4 if female == 1 & race_black == 1

**
** Data Reshape 
keep vote2005 vote2007 vote2009 vote2011 ///
	depression2005 depression2007 depression2009 depression2011 ///
	depress_effort2005 depress_hopeless2005 depress_nervous2005 depress_restless2005 depress_sad2005 depress_worthless2005 ///
	depress_effort2007 depress_hopeless2007 depress_nervous2007 depress_restless2007 depress_sad2007 depress_worthless2007 ///
	depress_effort2009 depress_hopeless2009 depress_nervous2009 depress_restless2009 depress_sad2009 depress_worthless2009 ///
	depress_effort2011 depress_hopeless2011 depress_nervous2011 depress_restless2011 depress_sad2011 depress_worthless2011 ///
	female race_black inter_cat ///
	educ_years2005 educ_years2007 educ_years2009 educ_years2011 ///
	church_attend2005 church_attend2007 church_attend2009 church_attend2011 ///
	married2005 married2007 married2009 married2011 ///
	age2005 age2007 age2009 age2011 ///
	pov_levell2005 pov_levell2007 pov_levell2009 pov_levell2011 ///
	news_follow2005 news_follow2007 news_follow2009 news_follow2011 ///
	health_self2005 health_self2007 health_self2009 health_self2011 ///
	health_ins2005 health_ins2007 health_ins2009 health_ins2011 ///
	ethnic_imp2005 ethnic_imp2007 ethnic_imp2009 ethnic_imp2011 ///
	aid_ind aid_fam
reshape long vote depression educ_years church_attend married age pov_levell news_follow health_self health_ins ethnic_imp depress_effort depress_hopeless depress_nervous depress_restless depress_sad depress_worthless, i(aid_ind aid_fam) j(year)

**
** Electon counter
gen election = .
replace election = 1 if year == 2005
replace election = 2 if year == 2007
replace election = 3 if year == 2009
replace election = 4 if year == 2011

**
** Midterm dummy
gen midterm = 0
replace midterm = 1 if year == 2007 | year == 2011

**
** Data structure
egen case_id = group(aid_fam aid_ind)
xtset case_id


********************************************************************************
** Section 2: Analyses

**
** Methods, Data, and Measures

* Age of sample [Table 1]
forvalues i=2005(2)2011{
sum age if year == `i'
}
* Overall mean and SD [Table 2]
forvalues i=2005(2)2011{
sum depression if year == `i'
}
* Alpha scores for depression scales [Table 2]
forvalues i=2005(2)2011{
alpha depress_effort depress_hopeless depress_nervous depress_restless depress_sad depress_worthless if year == `i', std item
}
* Sample size & maan depression by group [Tables 1 & 2]
forvalues j=1(1)4{
forvalues i=2005(2)2011{
sum depression if year == `i' & inter_cat == `j'
}
}
*Mean differences in depression across group [Table 2]
forvalues i=1(1)4{
pwmean depression, over(inter_cat) mcompare(tukey) effects
}
*

**
** The Depression-Participation Gap

* Multivariate regression of vote on depression [coefficients for Figure 2, Table A.8]
forvalues i=1(1)5{
matrix psid_gap`i' = J(1,2,.)
matrix coln psid_gap`i' = estimate se
}
*

xtlogit vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm, re
quietly: lincom depression
matrix psid_gap1[1,1] = r(estimate)
matrix psid_gap1[1,2] = r(se)

xtlogit vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 1, re
quietly: lincom depression
matrix psid_gap2[1,1] = r(estimate)
matrix psid_gap2[1,2] = r(se)

xtlogit vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 2, re
quietly: lincom depression
matrix psid_gap3[1,1] = r(estimate)
matrix psid_gap3[1,2] = r(se)

xtlogit vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 3, re
quietly: lincom depression
matrix psid_gap4[1,1] = r(estimate)
matrix psid_gap4[1,2] = r(se)

xtlogit vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 4, re
quietly: lincom depression
matrix psid_gap5[1,1] = r(estimate)
matrix psid_gap5[1,2] = r(se)

matrix rowname psid_gap1 = "Overall" 
matrix rowname psid_gap2 = "White Men" 
matrix rowname psid_gap3 = "White Women" 
matrix rowname psid_gap4 = "Black Men" 
matrix rowname psid_gap5 = "Black Women"

* Interaction term [Note in text about Figure 2]
xtlogit vote c.depression##inter_cat age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm, re

* Relative effect of depression [Table 3]
xtlogit vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm, re
sum depression educ_years church_attend age pov_levell
margins, at(depression = (.034149 1.3631184)) predict(pu0)
margins, at(educ_years = (9.997974 13.850986)) predict(pu0)
margins, at(church_attend = (1.124073 4.488937)) predict(pu0)
margins, at(age = (18 27)) predict(pu0)
margins, at(pov_levell = (-.2675374 2.0496146)) predict(pu0)

**
** Mitigating the Gap

* Income interaction models [Table 4, Table A.13]
xtlogit vote c.depression##c.pov_levell female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm, re
xtlogit vote c.depression##c.pov_levell age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 1, re
xtlogit vote c.depression##c.pov_levell age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 2, re
xtlogit vote c.depression##c.pov_levell age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 3, re
xtlogit vote c.depression##c.pov_levell age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 4, re

* Health insurance interaction models [Table 4, Table A.14]
xtlogit vote c.depression##health_ins female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm, re
xtlogit vote c.depression##health_ins age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 1, re
xtlogit vote c.depression##health_ins age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 2, re
xtlogit vote c.depression##health_ins age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 3, re
xtlogit vote c.depression##health_ins age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 4, re

* Religious attendance interaction models [Table 4, Table A.15]
xtlogit vote c.depression##c.church_attend female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm, re
xtlogit vote c.depression##c.church_attend age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 1, re
xtlogit vote c.depression##c.church_attend age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 2, re
xtlogit vote c.depression##c.church_attend age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 3, re
xtlogit vote c.depression##c.church_attend age educ_years pov_levell church_attend married health_self health_ins ethnic_imp election midterm if inter_cat == 4, re

* Group consciousness interaction models [Table 4, Table A.16, Figure 3]
xtlogit vote c.depression##c.ethnic_imp female race_black age educ_years pov_levell church_attend married health_self health_ins election midterm, re
xtlogit vote c.depression##c.ethnic_imp age educ_years pov_levell church_attend married health_self health_ins election midterm if inter_cat == 1, re
xtlogit vote c.depression##c.ethnic_imp age educ_years pov_levell church_attend married health_self health_ins election midterm if inter_cat == 2, re
xtlogit vote c.depression##c.ethnic_imp age educ_years pov_levell church_attend married health_self health_ins election midterm if inter_cat == 3, re
xtlogit vote c.depression##c.ethnic_imp age educ_years pov_levell church_attend married health_self health_ins election midterm if inter_cat == 4, re

xtlogit vote c.depression##c.ethnic_imp age educ_years pov_levell church_attend married health_self health_ins election midterm if inter_cat == 3, re
margins, at(depression = (0(.2)4) ethnic_imp = (1 7)) predict(pu0)
matrix group_bm = r(table)'
matrix list group_bm
svmat group_bm, name(group_bm)
gen even = !mod(_n,2)
egen dep_marg = seq(), f(0) t(20) b(2)
replace dep_marg = dep_marg / 5
replace dep_marg = . if _n > 42

graph twoway (rarea group_bm5 group_bm6 dep_marg if even == 0, fcolor("247 247 247") lcolor(black) lwidth(thin)) ///
			(line group_bm1 dep_marg if even == 0, color(black) lwidth(medthick)) ///
			(rarea group_bm5 group_bm6 dep_marg if even == 1, color("150 150 150") lcolor(black) lwidth(thin)) ///
			(line group_bm1 dep_marg if even == 1, color(black) lwidth(medthick)), ///
			legend(order(1 3) label(1 "Weak Group Consciousness") label(3 "Strong Group Consciousness") row(2) region(color(white)) symxsize(5) size(small) ring(0) position(11)) ///
			xlabel(0 0.5 1 1.5 2 2.5 3 3.5 4, labsize(2.5)) ///
			xtitle("Depressive Symptoms", size(4)) ///
			ylabel(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1, angle(horizontal) labsize(2.5) nogrid) ///
			ytitle("Probability of Voting", size(4)) ///
			scheme(s1mono) graphregion(fcolor(white)) ///
			name(group_bw1, replace)
			
drop group_bm* dep_marg
xtlogit vote c.depression##c.ethnic_imp age educ_years church_attend pov_levell married health_self health_ins election midterm if inter_cat == 3, re
margins, at(depression = (0 3) ethnic_imp = (1(.2)7)) predict(pu0)
matrix group_bm = r(table)'
matrix list group_bm
svmat group_bm, name(group_bm)
gen dep_marg = 1
replace dep_marg = 0 if _n < 32
egen gc_marg = seq(), f(5) t(35)
replace gc_marg = gc_marg / 5
replace gc_marg = . if _n > 62

graph twoway (rarea group_bm5 group_bm6 gc_marg if dep_marg == 1, color("247 247 247") lcolor(black) lwidth(thin))  ///
			(line group_bm1 gc_marg if dep_marg == 1, color(black) lwidth(medthick)) /// 
			(rarea group_bm5 group_bm6 gc_marg if dep_marg == 0, color("150 150 150") lcolor(black) lwidth(thin))  ///
			(line group_bm1 gc_marg if dep_marg == 0, color(black) lwidth(medthick)), ///
			legend(order(1 3) label(1 "Many Depressive Symptoms") label(3 "No Depressive Symptoms") row(2) region(color(white)) symxsize(5) size(small) ring(0) position(11)) ///
			xlabel(1 2 3 4 5 6 7, labsize(2.5)) ///
			xtitle("Group Consciousness", size(4)) ///
			ylabel(0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1, angle(horizontal) labsize(2.5) nogrid) ///
			ytitle("Probability of Voting", size(4)) ///
			scheme(s1mono) graphregion(fcolor(white)) ///
			name(group_bw2, replace)

* Empowerment thesis [Figure 4]
gen elect_co = 0
replace elect_co = 1 if election == 3 | election == 4
replace elect_co = . if election == .
xtlogit vote c.depression##elect_co female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp midterm, re
xtlogit vote c.depression##elect_co age educ_years pov_levell church_attend married health_self health_ins ethnic_imp midterm if inter_cat == 1, re
margins, at(depression = (0 1) elect_co = (0 1)) predict(pu0)
xtlogit vote c.depression##elect_co age educ_years pov_levell church_attend married health_self health_ins ethnic_imp midterm if inter_cat == 2, re
margins, at(depression = (0 1) elect_co = (0 1)) predict(pu0)
xtlogit vote c.depression##elect_co age educ_years pov_levell church_attend married health_self health_ins ethnic_imp midterm if inter_cat == 3, re
margins, at(depression = (0 1) elect_co = (0 1)) predict(pu0)
xtlogit vote c.depression##elect_co age educ_years pov_levell church_attend married health_self health_ins ethnic_imp midterm if inter_cat == 4, re
margins, at(depression = (0 1) elect_co = (0 1)) predict(pu0)

gen dep_gap = .
replace dep_gap = -1.6 if _n == 1
replace dep_gap = 3.0 if _n == 2
replace dep_gap = 11.2 if _n == 3
replace dep_gap = 5.2 if _n == 4
replace dep_gap = 16.9 if _n == 5
replace dep_gap = 0.1 if _n == 6
replace dep_gap = 5.6 if _n == 7
replace dep_gap = 7 if _n == 8

gen dep_gap_str = "."
replace dep_gap_str = "-2%" if _n == 1
replace dep_gap_str = "3%" if _n == 2
replace dep_gap_str = "11%" if _n == 3
replace dep_gap_str = "5%" if _n == 4
replace dep_gap_str = "17%" if _n == 5
replace dep_gap_str = "0%" if _n == 6
replace dep_gap_str = "6%" if _n == 7
replace dep_gap_str = "7%" if _n == 8

forvalues i=1(1)8{
gen dep_gap`i' = .
replace dep_gap`i' = dep_gap if _n == `i'
}
*

gen n_var = .
replace n_var = 11 if _n == 1
replace n_var = 10 if _n == 2
replace n_var = 8 if _n == 3
replace n_var = 7 if _n == 4
replace n_var = 5 if _n == 5
replace n_var = 4 if _n == 6
replace n_var = 2 if _n == 7
replace n_var = 1 if _n == 8

gen dep_gap_n = dep_gap
replace dep_gap_n = 0 if dep_gap < 0

twoway(bar dep_gap1 n_var, horizontal barwidth(0.75) lcolor(black) fcolor(white) lwidth(thin)) ///
		(bar dep_gap2 n_var, horizontal  barwidth(0.75) lcolor(black) fcolor(black) lwidth(thin)) ///
		(bar dep_gap3 n_var, horizontal  barwidth(0.75) lcolor(black) fcolor(white) lwidth(thin))  ///
		(bar dep_gap4 n_var, horizontal  barwidth(0.75) lcolor(black) fcolor(black) lwidth(thin)) ///
		(bar dep_gap5 n_var, horizontal  barwidth(0.75) lcolor(black) fcolor(white) lwidth(thin))  ///
		(bar dep_gap6 n_var, horizontal  barwidth(0.75) lcolor(black) fcolor(black) lwidth(thin)) ///
		(bar dep_gap7 n_var, horizontal  barwidth(0.75) lcolor(black) fcolor(white) lwidth(thin))  ///
		(bar dep_gap8 n_var, horizontal  barwidth(0.75) lcolor(black) fcolor(black) lwidth(thin)) ///
		(scatter n_var dep_gap_n, msymbol(i) mlabel(dep_gap_str) mlabposition(3) mlabsize(2.5) mcolor(black)), ///
		legend(order(1 2) label(1 "Pre-Obama") label(2 "Post-Obama") region(style(none)) position(1) ring(0) row(3) symxsize(5)) ///
		xlabel(0 5 10 15 20, labsize(2.5) angle(horizontal) nogrid) ///
		ylabel(10.5 `""White" "Men""' 7.5 `""White" "Women""' 4.5 `""Black" "Men""' 1.5 `""Black" "Women""', angle(horizontal) notick labgap(2)) ///
		ytitle(" ") ///
		xtitle("") ///
		xline(0, lcolor(gs10) lpattern(dash) noextend) ///
		xtitle("Predicted Depression-Participation Gap", size(4)) ///
		xscale(titlegap(4)) ///
		scheme(s1mono) graphregion(fcolor(white))
		
		
**
** Appendix

* Descriptive statistics, overall [Table A.2]
sum vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp if depression != .

* Correlations between variables [Table A.5]
pwcorr vote depression female race_black age educ_years pov_levell church_attend married health_self health_ins ethnic_imp if depression != .

* Effect of depression on each mitigator [Table A.20]
xtreg pov_level depression female race_black age educ_years church_attend married health_self health_ins ethnic_imp election midterm, re
xtlogit health_ins depression female race_black age educ_years pov_levell church_attend married health_self ethnic_imp election midterm, re
xtreg church_attend depression female race_black age educ_years pov_levell married health_self health_ins ethnic_imp election midterm, re
xtreg ethnic_imp depression female race_black age educ_years pov_levell church_attend married health_self health_ins election midterm, re
